package com.sinosoft.system.util.generate;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Map;



import freemarker.template.Configuration;
import freemarker.template.Template;


public class GenEntityMysqlFtl {

	public void doGenEntity(Map<String, Object> root,String ftlPath, String projectPath,String packgaePath){
        try {
        	//创建freemarker配置实例  
        	Configuration cfg=new Configuration();
			cfg.setDirectoryForTemplateLoading(new File(ftlPath));
			Template template = cfg.getTemplate("Entity.ftl");
			
			String realSavePath = projectPath+"//"+packgaePath.replace(".", "//");
			
			File newsDir = new File(realSavePath);  
	        if (!newsDir.exists()) {  
	            newsDir.mkdirs();  
	        }
			
	        Writer out = new OutputStreamWriter(new FileOutputStream(realSavePath+"//"+root.get("className")+".java"), "UTF-8");
			template.process(root, out);
			out.flush();
 
        } catch (Exception e) {		
			e.printStackTrace();
		} 
    }

}
